package com.pzhu.user.domain.vo.converter;

import com.mybatisflex.core.paginate.Page;
import com.pzhu.user.domain.entity.User;
import com.pzhu.user.domain.enums.UserSexEnum;
import com.pzhu.user.domain.vo.UserSearchVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import com.pzhu.base.common.utils.json.JSONUtils;
import com.pzhu.base.common.utils.result.PageData;

import java.util.List;

@Mapper(
        componentModel = MappingConstants.ComponentModel.SPRING,
        imports = {JSONUtils.class, UserSexEnum.class})
public interface UserSearchVOConverter {

    default PageData<UserSearchVO> convert(Page<User> userPage) {
        List<User> userList = userPage.getRecords();
        List<UserSearchVO> userSearchVOList = convert(userList);
        return new PageData<>(userSearchVOList, userPage.getTotalRow());
    }

    @Mapping(target = "address", ignore = true)
    @Mapping(target = "userId", source = "id")
    @Mapping(target = "gender", source = "gender.code")
    UserSearchVO convert(User user);

    List<UserSearchVO> convert(List<User> userList);
}
